package com.singularity.onelabel.publish;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.singularity.onelabel.R;
import com.singularity.onelabel.capsule.CreateCapsuleActiviity;
import com.singularity.onelabel.goal.CreateGoalActivity;
import com.singularity.onelabel.lable.CreateLabelActivity;
import com.singularity.onelabel.utils.ToastUtils;

/**
 * Created by Lenovo on 2018/12/15.
 */

public class PublishDialog extends Dialog implements View.OnClickListener{

    private OnDialogButtonClickListener mListener;
    //dialog的构造方法，必须实现一个
    public PublishDialog(@NonNull Context context) {
        // 设置弹窗的主题
        this(context,R.style.publish_dialog_style);
    }

    // dialog 的构造方法，必须实现一个
    public PublishDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public void setButtonClickListener(OnDialogButtonClickListener mListener){
        this.mListener = mListener;
    }

    public interface OnDialogButtonClickListener{
        void onLabelClicked();
        void onCapsuleClicked();
        void onGoalClicked();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.publish_dialog_layout);
        LinearLayout rootLayout = findViewById(R.id.publish_dialog_root_layout);
        LinearLayout labelLayout = findViewById(R.id.publish_memo_layout);
        LinearLayout capsuleLayout = findViewById(R.id.publish_capsule_layout);
        LinearLayout targetLayout = findViewById(R.id.publish_target_layout);
        // 设置最外层父布局的点击事件
        rootLayout.setOnClickListener(this);
        // 设置发布标签按钮的点击事件
        labelLayout.setOnClickListener(this);
        // 设置发布胶囊按钮的点击事件
        capsuleLayout.setOnClickListener(this);
        // 设置发布目标按钮的点击事件
        targetLayout.setOnClickListener(this);

        // 设置 Dialog 的参数
        initDialogParam();
    }

    private void initDialogParam() {
        // 获取窗体的实例
        Window window = getWindow();
        // 获取窗体管理类实例
        WindowManager windowManager = window.getWindowManager();
        // 获取窗体的布局参数实例
        WindowManager.LayoutParams params= window.getAttributes();
        // 设置窗体的宽高属性
        params.width = windowManager.getDefaultDisplay().getWidth();
        params.height = windowManager.getDefaultDisplay().getHeight();
        // 设置窗体的透明度属性
        params.alpha = 0.8f;
        // 设置窗体的属性
        window.setAttributes(params);

    }

    @Override
    public void onClick(View view) {
        // 设置Dialog各个view的点击事件
        switch (view.getId()){
            case R.id.publish_dialog_root_layout:
                //点击任意一个地方，弹窗消失
                dismiss();
                break;
            case R.id.publish_memo_layout:
                // 点击发布便签按钮，跳转到发布便签的页面
                if (mListener != null){
                    mListener.onLabelClicked();
                }
                break;
            case R.id.publish_capsule_layout:
                // 点击发布胶囊按钮，跳转到发布胶囊的页面
                if (mListener != null){
                    mListener.onCapsuleClicked();
                }
                break;
            case R.id.publish_target_layout:
                // 点击发布目标按钮，跳转到发布目标的页面
                if (mListener != null){
                    mListener.onGoalClicked();
                }
                break;
            default:
                break;
        }
    }
}
